<template>
  <div v-if="!Weixin_" class="header" :style="{ background: background,paddingTop:Height+'px'}">
    <div class="wid96">
      <div class="back_" @click="backAciton">
        <img v-if="image_=='0'" src="../public/img/other/fanhui_hei.png" alt="" />
        <img class="back_trfom" v-else src="../public/img2/level_new/wealth_back_icon@2x.png" alt="" />
      </div>
      <div class="title" :style="{ color: color,fontSize:size}">
        <slot>{{title}}</slot>
        <slot name="taber_tab"></slot>
      </div> 
      <div class="share">
        <template>
          <slot name="share"></slot>
          <slot name="share_dian"></slot>
        </template>
      </div>
    </div>
  </div>
</template>
<script>
  //  :Weixin_="true"  true小程序隐藏自定义头部false显示
  import wx from 'weixin-js-sdk'
  import {
    Toast
  } from 'vant'
  export default {
    props: {
      Weixin_: false, //是否微信浏览器
      title: "",
      pathName: '',
      background: "",
      color: "",
      image_: "", //0黑1白
      size: '',
    },
    data() {
      return {
        Height: '',
      }
    },
    created() {
      let that = this;
      var u = navigator.userAgent;
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isiOS) {
          if (window.webkit) {
            window.webkit.messageHandlers.getStatusBarHeight.postMessage({});
            //Vue的方法给原生调用，则需要把方法挂在Window下面
            window.sendStatusBarHeight = this.sendStatusBarHeight;
          }
        } else {
          that.Height = app.getStatusBarHeight() / window.devicePixelRatio;
          this.$emit('getHeight', 48 + that.Height)
        }
    },
    components: {},
    methods: {
      sendStatusBarHeight(Height) {
        this.Height = Height;
        this.$emit('getHeight', 48 + Height)
      },
      backAciton() {
        var ua = navigator.userAgent.toLowerCase(); //微信小程序 
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
          wx.miniProgram.navigateBack({delta: 1})
        } else {
          if (this.$store.state.pathName == '/Confession' || this.$store.state.pathName == "/dress_new") {
            this.$router.push(this.$store.state.pathName);
          } else {
            if (window.isiOS) {
              console.log("iOS返回事件");
              window.webkit.messageHandlers.backAction.postMessage({});
            } else {
              console.log("安卓返回事件");
              app.backAction();
            }
          }
        }
      }
    }
  }
</script>

<style scoped lang="less">
  .header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    z-index: 999;

    .wid96 {
      width: 96vw;
      margin: 0 auto;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .back_ {
      width: 20vw;
      height: 100%;
      display: flex;
      align-items: center;

      img {
        width: 2.2vw;
        padding-left: 2vw;
      }

      .back_trfom {
        // transform: rotate(180deg);
      }
    }

    .title {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 48px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 400;
    }

    .share {
      width: 20vw;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
</style>